package tralala.client.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;

import tralala.client.controller.TralalaController;

public class VRep implements ActionListener, WindowListener {

	private JFrame frame;
	private JPanel panelDesc;
	private JPanel panelDescTitulo;
	private JPanel panelDescArtista;
	private JPanel panelLetra;
	private JPanel panelBtn;
	private JTextField txtTitulo;
	private JTextField txtArtista;
	private JTextPane txtLetra;
	private JScrollPane scrollPane;
	private JButton btnVolver;
	private JButton btnSalir;
	private TralalaController Tcontroller;

	public static void main(String[] args) {
		new VRep(null);
	}

	public VRep(TralalaController Tcontroller) {
		this.Tcontroller = Tcontroller;
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		panelDesc = new JPanel();
		panelDesc.setBorder(new EmptyBorder(0, 0, 0, 0));
		panelDescTitulo = new JPanel();
		panelDescArtista = new JPanel();
		panelLetra = new JPanel();
		panelBtn = new JPanel();
		panelBtn.setBorder(new EmptyBorder(5, 5, 5, 5));
		txtTitulo = new JTextField();
		txtArtista = new JTextField();
		txtLetra = new JTextPane();
		btnVolver = new JButton("Volver");
		btnSalir = new JButton("Salir");

		panelBtn.setBackground(new Color(204, 204, 255));
		panelDesc.setBackground(new Color(204, 204, 255));
		panelDescTitulo.setBackground(new Color(204, 204, 255));
		panelDescArtista.setBackground(new Color(204, 204, 255));
		panelLetra.setBackground(new Color(204, 204, 255));
		frame.setTitle(Tcontroller.getCancion().getTitulo());

		panelDesc.setLayout(new java.awt.GridLayout(1, 0));

		panelDescTitulo.setLayout(new java.awt.GridLayout(1, 0));
		panelDescTitulo.setBorder(javax.swing.BorderFactory.createTitledBorder(
				null, "Titulo", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1,
						12)));

		txtTitulo.setText(Tcontroller.getCancion().getTitulo());
		txtTitulo.setEditable(false);
		txtTitulo.setHorizontalAlignment(SwingConstants.CENTER);

		panelDescArtista.setLayout(new java.awt.GridLayout(1, 0));
		panelDescArtista.setBorder(javax.swing.BorderFactory
				.createTitledBorder(null, "Artista", TitledBorder.CENTER,
						TitledBorder.DEFAULT_POSITION, new java.awt.Font(
								"Tahoma", 1, 12)));

		txtArtista.setText(Tcontroller.getCancion().getArtista());
		txtArtista.setEditable(false);
		txtArtista.setHorizontalAlignment(SwingConstants.CENTER);

		panelDescTitulo.add(txtTitulo);
		panelDescArtista.add(txtArtista);

		panelDesc.add(panelDescTitulo);
		panelDesc.add(panelDescArtista);
		frame.getContentPane().add(panelDesc, BorderLayout.NORTH);

		panelLetra.setLayout(new java.awt.GridLayout(0, 1));
		panelLetra.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
				"Letra", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION,
				new java.awt.Font("Tahoma", 1, 12)));

		StyledDocument document = new DefaultStyledDocument();
		Style defaultStyle = document.getStyle(StyleContext.DEFAULT_STYLE);
		StyleConstants.setAlignment(defaultStyle, StyleConstants.ALIGN_CENTER);
		txtLetra = new JTextPane(document);
		txtLetra.setText(Tcontroller.getCancion().getLetra());

		scrollPane = new JScrollPane(txtLetra);
		txtLetra.setEditable(false);
		panelLetra.add(scrollPane);
		frame.getContentPane().add(panelLetra, BorderLayout.CENTER);

		panelBtn.setLayout(new java.awt.GridLayout(1, 0));
		btnVolver.setFont(new Font("Tahoma", Font.PLAIN, 12));
		btnVolver.addActionListener(this);
		btnSalir.setFont(new Font("Tahoma", Font.PLAIN, 12));
		btnSalir.addActionListener(this);

		panelBtn.add(btnVolver);
		panelBtn.add(btnSalir);
		frame.getContentPane().add(panelBtn, java.awt.BorderLayout.SOUTH);
		frame.setVisible(true);
	}

	@Override
	public void windowActivated(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowClosed(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowClosing(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowDeactivated(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowDeiconified(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		JButton btnPresionado = (JButton)arg0.getSource();
		if (btnPresionado == btnSalir) {
			frame.setVisible(false);
			frame.dispose();
		} else if (btnPresionado == btnVolver) {
			
		}
	}

}
